<template>
    <view class="category">
        <guess v-for="(item,index) in category.children" :title="item.name" :guess-list="item.goods"></guess>
    </view>
</template>

<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import useCategoryStore from "@/pinia/modules/categoryStore";
import { storeToRefs } from "pinia";
import Guess from "@/components/guess.vue";

const props = defineProps<{
    id: string
}>();

const categoryStore=useCategoryStore()

const {category}=storeToRefs(categoryStore)

/*获取商品分类的函数*/
const fetchCategory = async () => {
  try {
      await categoryStore.fetchCategory(props.id)
  }catch (error:any) {
      await uni.showToast({ title: error.message, icon: "error", duration: 2000 });
  }
}

onLoad(()=>{
    fetchCategory()
})
</script>


<style scoped lang="scss">
page{
    background-color: #f4f4f4;
}
</style>
